from . import math


class fraction:
    def __init__(self, denominator, molecular, ValueRounds=10, auto_reduction=True):
        """
        denominator  :分母
        -----------------
        molecular    :分子
        """
        self.denominator = denominator
        self.molecular = molecular
        self.ValueRounds = ValueRounds
        self.AutoReduction = auto_reduction
        self.value = self._get_value()
        self._autorun()

    def _autorun(self):
        """自动运行"""
        if self.AutoReduction:
            self._reduction()

    def _reduction(self):
        """化简"""
        MaxFactor = math.MAXFactor(self.denominator, self.molecular)
        if MaxFactor == 1:
            pass
        else:
            self.denominator = self.denominator / MaxFactor
            self.molecular = self.molecular / MaxFactor

    def _get_value(self):
        """
        获取值
        return:值
        """
        value = round(self.denominator / self.molecular, self.ValueRounds)
        return value


def add(Add1: fraction, Add2: fraction, after_reduction=True):
    """对两个分数进行加法"""
